/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fhv.itb.ec.fruitshop;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Malcolm
 */
@Stateless
public class FruitFacade implements FruitFacadeLocal {
    @PersistenceContext
    private EntityManager em;

    public void create(Fruit fruit) {
        em.persist(fruit);
    }

    public void edit(Fruit fruit) {
        em.merge(fruit);
    }

    public void remove(Fruit fruit) {
        em.remove(em.merge(fruit));
    }

    public Fruit find(Object id) {
        return em.find(Fruit.class, id);
    }

    public List<Fruit> findAll() {
        return em.createQuery("select object(o) from Fruit as o").getResultList();
    }

}
